var app = getApp();
var time = require("../../../utils/util.js");
Page({
  data: {
    pageId: 0,
    message: "",
    guan: "",
    imgName: ["厂房外景", "办公场所", "常规设施", "营业执照"],
    imgNameId: "",
    showPhotoImg: false,
    statusBarHeight: app.globalData.statusBarHeight //状态栏高度
  },
  onLoad: function(e) {
    var openid = wx.getStorageSync("openid");
    var myuid = wx.getStorageSync("uid");
    this.setData({
      uid: e.uid,
      myuid: myuid
    })
    var that = this;
    //主页内容
    wx.request({
      url: 'https://www.mamingwang.cn/api/index/index',
      data: {
        openid: openid,
        uid: e.uid
      },
      method: "post",
      success(res) {
        console.log(res);
        that.setData({
          message: res.data.message,
          guan: res.data.message.guan ? res.data.message.guan : "",
          phone: res.data.message.phone
        })
      }
    })
    //我的产品与文章
    wx.request({
      url: 'https://www.mamingwang.cn/api/index/message',
      data: {
        openid: openid,
        uid: e.uid
      },
      method: "post",
      success(res) {
        if (res.data) {
          //字符串
          for (var i = 0; i < res.data.message.length; i++) {
            if (res.data.message[i].type == 2) {
              if (res.data.message[i].content.length > 24) {
                res.data.message[i].content = res.data.message[i].content.substring(0, 24) + '...'
              }
            }
            //时间
            let d = new Date(res.data.message[i].createtime.replace(/-/g, '/')).getTime();
            res.data.message[i].createtime = time.timeHandle(d);
          }
          that.setData({
            messageCp: res.data.message,
          })
        }
      }
    })
  },
  //关注
  followFans: function() {
    var openid = wx.getStorageSync("openid");
    var that = this;
    wx.request({
      url: 'https://www.mamingwang.cn/api/index/focus',
      data: {
        openid: openid,
        aid: that.data.uid
      },
      method: "post",
      success(res) {
        that.setData({
          guan: 1
        })
      }
    })
  },
  //取消关注
  noFollowFans: function() {
    var openid = wx.getStorageSync("openid");
    var that = this;
    wx.request({
      url: 'https://www.mamingwang.cn/api/index/nofocus',
      data: {
        openid: openid,
        aid: that.data.uid
      },
      method: "post",
      success(res) {
        that.setData({
          guan: 0
        })
      }
    })
  },
  //拨号
  call: function(e) {
    var that = this;
    var openid = wx.getStorageSync("openid");
    wx.request({
      url: 'https://www.mamingwang.cn/api/xinxi/user_bohao',
      data: {
        openid: openid,
        uid: e.currentTarget.dataset.uid,
      },
      method: "post",
      success(res) {
        console.log(res)
        if (res.data.code == -3) {
          wx.showToast({
            title: '今日拨号次数已达上限',
            icon: "none",
            duration: 1500,
            mask:true
          })
        } else {
          wx.makePhoneCall({
            phoneNumber: that.data.phone,
            success(res) {}
          })
        }
      }
    })
  },
  //分享
  share: function(e) {
    var openid = wx.getStorageSync("openid");
    wx.request({
      url: 'https://www.mamingwang.cn/api/xinxi/user_share',
      data: {
        openid: openid,
        uid: e.currentTarget.dataset.uid
      },
      method: "post",
      success(res) {
        console.log(res)
      }
    })
  },
  //弹窗
  removetouchmove: function() {},
  showPhotoImg: function(e) {
    this.setData({
      showPhotoImg: !this.data.showPhotoImg,
      imgNameId: e.currentTarget.id
    })
  },
  //我的主页
  goZhuYe: function() {
    this.setData({
      pageId: 0
    })
  },
  //我的产品
  goChanPin: function() {
    this.setData({
      pageId: 1
    })
  },
})